using Godot;
using System;

public partial class NBox : Area2D
{
	[Export] public CItem mItem;
	TextureRect mOpen;
	TextureRect mClose;
	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
		mOpen = GetNodeOrNull<TextureRect>("Open");
		mClose = GetNodeOrNull<TextureRect>("Close");

		mOpen.Visible = false;

		BodyEntered += (n) => _bodyEnter(n);
	}

	void _bodyEnter(Node2D n)
	{
		if (n is NCharacter cha)
		{
			if (mItem!=null && cha.pickItem(mItem))
			{
				mClose.Visible = false;
				mOpen.Visible = true;
				mItem = null;

			}
		}
	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
	}
}
